﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LINQLambda
{
    class MainClass
    {
        static void Main(string[] args)
        {
            //StringBuilder stringb = new StringBuilder("This is a big stringbuilder with alot of words in it");
            //Console.WriteLine(stringb.Substring(5, 10));

            //int[] arr = { 1, 2, 3, 4, 5, 6, 7 };
            //string[] arrstring = { "abs", "babs", "ueruewru" };
            //Console.WriteLine(arr.SumElements());
            //Console.WriteLine(arr.Product());
            //Console.WriteLine(arr.AverageSum());
            //Console.WriteLine(arrstring.MaxElement());
            //Console.WriteLine(arrstring.MinElement());

            Student[] students = { new Student("Ivan", "Petrov", 20),
                                     new Student("Georgi", "Georgiev", 18),
                                     new Student("Andrey", "Geshev", 25),
                                     new Student("Stoqn", "Kalev", 22),
                                     new Student("Ivan", "Kolarov", 23)
                                 };
            #region First name < last name
            Console.WriteLine("First name < lastname LINQ");
            var fnbln =
                from student in students
                where (student.FirstName.CompareTo(student.LastName) < 0)
                select student;
            
            foreach (Student student in fnbln)
            {
                Console.WriteLine(student);
            }

            Console.WriteLine("\nFirst name < lastname Lambda");
            var studs = students.Where(student => student.FirstName.CompareTo(student.LastName) < 0);

            foreach (Student student in studs)
            {
                Console.WriteLine(student);
            }
            #endregion

            #region 18 < Age > 24

            Console.WriteLine("\n18 < Age > 24 LINQ");
            var middleAgeStudents =
                from student in students
                where (student.Age > 18 && student.Age < 24)
                select student;

            foreach (var student in middleAgeStudents)
            {
                Console.WriteLine(student);
            }

            Console.WriteLine("\n18 < Age > 24 Lambda");
            var studentsAge = students.Where(student => student.Age > 18 && student.Age < 24);

            foreach (var student in studentsAge)
            {
                Console.WriteLine(student);
            }
            #endregion

            Console.WriteLine("\nSorted by two names");
            var studentsSortby2 = students.OrderBy(student => student.FirstName).ThenBy(student => student.LastName);

            foreach (var student in studentsSortby2)
            {
                Console.WriteLine(student);
            }

            Console.WriteLine("\nNumbers devided by 3 and 7 Lambda");
            int[] numbers = { 1, 2, 323, 32, 42, 3, 25, 34, 34, 2354, 54, 23, 2354, 42343, 4535, 67, 87, 54, 54, 21 };

            var numdev37 = numbers.Where(num => num % 7 == 0 && num % 3 == 0);

            foreach (var num in numdev37)
            {
                Console.Write(num + " ");
            }

            Console.WriteLine("\nNumbers devided by 3 and 7 LINQ");
            var numsdev37 =
                from num in numbers
                where num % 7 == 0 && num % 3 == 0
                select num;

            foreach (var num in numsdev37)
            {
                Console.Write(num + " ");
            }

            Console.WriteLine("\n\nString.CapitalWordsCount");

            string text = "jasdjhd asd asd asd d sasd asd fsdfj fjk sdfjk sdkfj";
            Console.WriteLine(text.CapitaliseFirstLetterInWords());
            Console.WriteLine();
        }
    }
}
